#ifndef DIALOG_H
#define DIALOG_H

#include <QtGui/QDialog>
#include "optiondialog.h"
#include <QHostAddress>
#include <QTcpSocket>
#include <QTcpServer>
#include <QTextTableFormat>
#include <QMultiHash>
#include <QList>
namespace Ui
{
    class DialogClass;
    class Option;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    Dialog(QWidget *parent = 0);
    //void convertIntToChar(ing msg[],char des[]);
    void sendMsg(int,int,QTcpSocket*);
    ~Dialog();
private:
    void appendMessage(const QString &from,const QString &message);//消息本地显示
private slots:
    void setOption();
    void getOption(bool isClient,QHostAddress *ip,int port); // 获取配置窗口的信息
    void returnPressed();
    void connectedToServer();//连接服务器成功
    void messageArrived();   //有数据到达
    void acceptConnection();//新的连接
    //void timerEvent(QTimerEvent* event);


private:
    Ui::DialogClass *ui;
    optionDialog *option;
    bool isClient ; //服务器客户端标识
    bool isConnected; //是否连结
    QHostAddress ip; //服务器端IP地址
    int port;
    QTextTableFormat  tableFormat;
    QTcpSocket tcpClient; //用于连接服务器的socket
    QTcpServer tcpServer; //用于监听的socket
    QTcpSocket  *tcpServerConnection;//用于服务器接受数据的socket
    QByteArray outBlock; //发送信息用的
    QMultiHash<QHostAddress, QTcpSocket *> peers; //用来保存所有的连接
    QList<QTcpSocket*> connectedSockets;

};

#endif // DIALOG_H
